package facilius.controller.action.disciplina;

import facilius.model.ServiceLocator;
import facilius.model.pojo.Disciplina;
import java.util.HashMap;
import java.util.Map;
import org.mentawai.core.BaseAction;

/**
 *
 * @author Graciano
 */
public class DisciplinaShowFormAction extends BaseAction {

    @Override
    public String execute() throws Exception {
        String consequence = ERROR;
        String formAction = "DisciplinaCreate.mtw";
        this.preload();
        try {
            Long id = input.getLong("id");
            if (id != null && id > 0) {
                Disciplina disciplina = ServiceLocator.getDisciplinaService().readById(id);
                output.setValue("id", disciplina.getId());
                output.setValue("nome", disciplina.getNome());
                output.setValue("descricao", disciplina.getDescricao());
                output.setValue("cursoId", disciplina.getCurso().getId());
                formAction = "DisciplinaUpdate.mtw";
            }
            consequence = SUCCESS;
            output.setValue("formAction", formAction);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return consequence;
    }

     public void preload() throws Exception {
        Map<String, Object> criteria = new HashMap<String, Object>();
        Map<String, String> options = ServiceLocator.getCursoService().getOptions(criteria);
        output.setValue("cursoOptions", options);
    }
}
